@extends("admin.layout.main")

@section("content")
    <style>
        .x-margin{
            margin: 5px;
        }
        .ivu-table td.no_padding>.ivu-table-cell{
            padding-left: 0;
            padding-right: 0;
        }
        .ivu-table th.demo-table-info-column{
            background-color: #2db7f5;
            color: white;
        }
    </style>
    <div id="app" >
        {{--编辑框--}}
        <Modal v-model="editProModal" width="360">
            <div>
                <div  class="x-margin-10">
                    <label>时间 : </label>
                    <span>
                        <Date-Picker type="datetimerange" v-model="date_range" split-panels placeholder="选择时间" style="width: 220px"></Date-Picker>
                    </span>

                </div>
                <p class="x-margin-10"><label>商品 : </label> <i-input v-model="origin_prod_id" style="width:220px" placeholder="请填写商品id"></i-input></p>
                <p class="x-margin-10"><label>订单 : </label> <i-input v-model="order_id" style="width:220px" placeholder="请填写订单id"></i-input></p>
                <p class="x-margin-10"><label>成本 : </label> <i-input v-model="cost_price" style="width:220px" ></i-input></p>
                <p class="x-margin-10"><label>快递 : </label> <i-input v-model="express_fee" style="width:220px" ></i-input></p>
                <p class="x-margin-10"><label>厂家 : </label> <i-input v-model="manu_name" style="width:220px" ></i-input></p>
                <p class="x-margin-10"><label>退款 : </label> <i-input v-model="refund_reason" style="width:220px" placeholder="请输入退款理由"></i-input></p>
            </div>
            <div slot="footer">
                <i-button type="primary" size="large" long  @click="orderEdit()">提交</i-button>
            </div>
        </Modal>
        {{--粉丝备注--}}
        <Modal v-model="fansModal" title="备注粉丝" width="360" @on-ok="storeMarkFans">
            <span>
                昵称:
                  <i-input v-model="fans.nickname" long></i-input>
            </span>
            <span>
                手机号:
                  <i-input v-model="fans.phone" disabled long></i-input>
            </span>
        </Modal>
        {{--退款登记--}}
        <Modal v-model="refundModal" title="线下退款登记"   :mask-closable="false" width="360" @on-ok="storeMarkRefund">
        <span>
                单号:
                  <i-input v-model="refund.order_id" disabled long></i-input>
            </span>
            <span>
                状态:
                     <i-select v-model="refund.status"  placeholder="请选择线下处理状态">
                        <i-option  value="0">未处理</i-option>
                         <i-option value="1">支付宝</i-option>
                         <i-option value="2">微信</i-option>
                    </i-select>
            </span>
            <span>
                线下货款:<span style="color: red;">（线下退款给用户【贷款金额】）</span>
                <i-input type="number" v-model="refund.unline_payment"  long></i-input>
            </span>
            <span>
                线下快递费:<span style="color: red;">（补快递费、不退货补差价在这边填写）</span>
                <i-input type="number" v-model="refund.unline_express_fee"  long></i-input>
            </span>
            <span>
                承担者:
                   <radio-group v-model="refund.unline_trager">
                        <Radio label="公司"></Radio>
                        <Radio label="厂家"></Radio>
                   </radio-group>
                <span style="color: red;">（必填）</span>
            </span>
            <br/>
            <span>
                线下备注:
                  <i-input v-model="refund.unline_mark" type="textarea" :rows="4" long></i-input>
            </span>

        </Modal>
        {{--主体代码--}}
        <Row type="flex" justify="center" align="middle">
            <Spin size="large" fix v-if="spinShow"></Spin>
            <i-col span="23" style="margin-top: 20px;">
                <span>
                    店铺:
                    <i-select v-model="search.shop_id" multiple placeholder="请选择店铺" style="width:120px">
                        <i-option  value="">全部</i-option>
                        <i-option v-for="shop of shops" :value="shop.shop_id">@{{shop.shop_name}}</i-option>
                    </i-select>
                </span>
                <span>
                    开始时间:
                     <date-picker type="datetime"
                                  format="yyyy-MM-dd HH:mm:ss"
                                  :value="defaultStartTime"
                                  placeholder="选择开始日期" style="width: 120px"
                    @on-change="dateStartFormat">
                    </date-picker>
                </span>
                <span>
                    &nbsp&nbsp&nbsp结束时间:
                     <date-picker type="datetime"
                                  format="yyyy-MM-dd HH:mm:ss"
                                  :value="defaultEndTime"
                                  placeholder="选择结束时间" style="width: 120px"
                    @on-change="dateEndFormat">
                    </date-picker>
                </span>

                <span style="padding-left: 10px">
                      <i-button  type="primary" @click="today">切换当天</i-button>
                </span>

                <span>
                    &nbsp&nbsp&nbsp订单号:
                     <i-input v-model="search.order_id" style="width:150px"></i-input>
                </span>

                <span>
                    &nbsp&nbsp&nbsp商品id:
                     <i-input v-model="search.origin_prod_id" style="width:150px"></i-input>
                </span>
                <span>
                    &nbsp&nbsp&nbsp电话:
                     <i-input v-model="search.post_tel" style="width:150px"></i-input>
                </span>
                <a :href="combine_link" style="display: inline-block;margin-left: 15px;">订单下载</a>


            </i-col>

        </Row>

        <Row type="flex" justify="center" align="middle">
            <i-col span="23" style="margin-top: 20px;">
                <span>
                    收件人:
                     <i-input v-model="search.post_receiver" style="width:150px"></i-input>
                </span>
                <span>
                    &nbsp&nbsp地址:
                     <i-input v-model="search.detail" style="width:150px"></i-input>
                </span>
                <span>
                    &nbsp&nbsp退款理由:
                     <i-input v-model="search.refund_reason" style="width:150px"></i-input>
                </span>
                <span>
                   &nbsp&nbsp订单状态:
                    <i-select v-model="search.status" placeholder="请选择状态" style="width:100px">
                        <i-option  :value="0">全部</i-option>
                        <i-option :value="item.val" v-for="item of status_arr">@{{ item.text }}</i-option>
                    </i-select>
                </span>
                <span>
                   &nbsp&nbsp回填转态:
                    <i-select v-model="search.back_status" placeholder="请选择状态" style="width:100px">
                        <i-option  value="0">全部</i-option>
                        <i-option  value="1">有回填（成本）</i-option>
                        <i-option  value="2">无回填（成本）</i-option>
                    </i-select>
                </span>
                <span>
                   &nbsp&nbsp主播:
                    <i-select v-model="search.liver" placeholder="请选择主播" style="width:150px">
                        <i-option  :value="0">全部</i-option>
                        <i-option :value="item.name" v-for="(item,index) in livers">@{{ item.name }}</i-option>
                    </i-select>
                </span>
            </i-col>
        </Row>
        <Row type="flex"  >
            <i-col style="margin-top: 15px;margin-left: 18px">
                <span >
                  <i-button  type="primary" @click="searchList">搜索</i-button>
                </span>

                <span >
                  <i-button  type="warning" @click="editProModalUp()">编辑商品</i-button>
                </span>

                <span >
                  <i-button  type="error" @click="updateOrder('')">同步订单(半个月)</i-button>
                </span>

                <span >
                  <i-button  type="error" @click="updateOrder(2)">同步订单(最近两天)</i-button>
                </span>

                <span >
                  <Checkbox v-model="single" style="color: red;font-size: 11px;margin-left: 5px" @on-change="setTimeUpdate">开启定时采集</Checkbox>
                </span>

                <span style="width: 100px;display: inline-block">
                     <Upload action="/admin/order/import" :data="data"  :on-success="onSucc"  :show-upload-list="showUpList">
                        <i-button icon="ios-cloud-upload-outline">导入订单</i-button>
                    </Upload>
                </span>

                <span style="padding-left: 10px">
                      <a href="/demo/放心购.xlsx" >导入模板</a>
                </span>
            </i-col>

            <i-col style="width: 90% ;margin:20px">
                <Card>

                    <div  style="display:inline-block;width: 250px;margin: 10px;border-right: 1px solid darkgrey" v-for="card of cards" :key="card.order_status">
                        <div >
                            订单状态 : @{{ card.order_status_text }}
                        </div>
                        <div >
                            订单数量 : @{{ card.order_count }}
                        </div>
                        <div >
                            订单金额 : @{{ card.shop_total_amount }}
                        </div>
                        <div style="color: red">回填统计</div>
                        <div>(用户付款/订单数/成本/利润/利润率)</div>
                        <div>
                           @{{ card.text }}
                        </div>
                    </div>

                </Card>
            </i-col>
        </Row>

        <Row type="flex" justify="center" align="middle" >
            <i-col span="23" style="margin-top: 20px">
                <i-table   :data="tableData" :columns="tableColumns" >
                </i-table>
            </i-col>
        </Row>

        <Row type="flex" justify="center" align="middle" >
            <i-col span="23" style="margin-top: 20px">
                <i-table  ref="selection" :data="tableData1" :columns="tableColumns1" :height="750">
                </i-table>
            </i-col>
        </Row>
        <Row type="flex" justify="center" class="code-row-bg">
            <i-col>
                <Page
                        size="small"
                        :total="page.total"
                        :current="page.current"
                        :page-size="page.pageSize"
                        show-total
                        show-elevator
                        @on-change="orderList">
                </Page>
            </i-col>
        </Row>

    </div>
    <script src="/js/layer/layer.js"></script>
    <script src="/js/vue.js"></script>
    <script  src="/js/iview.js"></script>
    <script  src="/js/axios.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data() {
                return {
                    data:{
                        token : '',
                    },
                    showUpList:false,
                    token:'',
                    tableColumns: [

                        {
                            title: '主播',
                            key: 'name',
                            width:80,
                        },
                        {
                            title: '总客数量 | 新客数量',
                            width:150,
                                render:(h,params) => {
                                    let customer_total_count = params.row.customer_total_count + ' | ';
                                    let customer_new_total_count = params.row.customer_new_total_count;
                                    return h('div', {
                                        style: {
                                            'text-align': 'center',
                                        }
                                    },
                                    [
                                        h('span',{
                                            style:{
                                                'color':'green',
                                                'font-size':'15px'
                                            },
                                        },customer_total_count),
                                        h('span',{
                                            style:{
                                                'color':'red',
                                                'font-size':'15px'
                                            },
                                        },customer_new_total_count)
                                    ])
                                }
                        },

                        {
                            title: "订单",
                            className: 'no_padding',
                            render: (h, params) => {
                                return h("div", [
                                    h("Table", {
                                        props: {
                                            columns: [
                                                {
                                                    title:"订单状态",
                                                    key: "order_status_text",
                                                    className:'demo-table-info-column'
                                                },
                                                {
                                                    title:"订单数量",
                                                    key:"order_count",
                                                    className:'demo-table-info-column'
                                                },
                                                {
                                                    title:"金额",
                                                    key:"shop_total_price",
                                                    className:'demo-table-info-column'
                                                },
                                                {
                                                    title:"优惠券金额",
                                                    key:"amount",
                                                    render:(h,params) => {
                                                        let coupon_total_amount = params.row.coupon_total_amount;
                                                        return h('div', {
                                                        }, coupon_total_amount)
                                                    },
                                                    className:'demo-table-info-column',
                                                },
                                                {
                                                    title:"回填成本统计(用户付款/订单数/成本/利润/利润率)",
                                                    width: 400,
                                                    render:(h,params) => {

                                                        text = '暂无';
                                                        let back_order_count = params.row.back_order_count;
                                                        let back_shop_total_price = params.row.back_shop_total_price;
                                                        let back_cost_total_price = params.row.back_cost_total_price;
                                                        if(back_order_count){
                                                            let back_profit = parseInt(back_shop_total_price - back_cost_total_price);
                                                            let back_profit_rate = Math.round(back_profit / back_shop_total_price * 100) + '%'
                                                            text = back_shop_total_price + ' / ' + back_order_count + ' / '
                                                                + back_cost_total_price + ' / '+ back_profit + ' / ' + back_profit_rate
                                                        }

                                                        return h('div', {
                                                        }, text)
                                                    },
                                                    className:'demo-table-info-column'
                                                }
                                            ],
                                            data: params.row.infos
                                        },
                                    }),
                                ]);
                            }
                        },
                    ],
                    tableData: [],
                    tableColumns1: [
                        {
                            type: 'index',
                            title:'序号',
                            width: 60
                        },
                        {
                            title:'退款登记',
                            width:'100',
                            render:(h,params) => {
                                let local_order_status = params.row.local_order_status;

                                if(local_order_status == 1){
                                    return h('div',{
                                        style:{
                                            'color':'green',
                                            'font-size':'12px'
                                        },
                                        on: {
                                            click: () => {
                                                this.markStatus(params.row)
                                            }
                                        }
                                    },'支付宝');
                                }else  if(local_order_status == 2){
                                    return h('div',{
                                        style:{
                                            'color':'green',
                                            'font-size':'12px'
                                        },
                                        on: {
                                            click: () => {
                                                this.markStatus(params.row)
                                            }
                                        }
                                    },'微信');
                                }else{
                                    return h('Button',{
                                        props: {
                                            type: 'primary',
                                            size: 'small',
                                        },
                                        on: {
                                            click: () => {
                                                this.markStatus(params.row)
                                            }
                                        }
                                    },'登记');
                                }

                            }
                        },
                        {
                            title:'订单状态',
                            width:'100',
                            key:'order_status_text',
                        },
                        {
                            title: '店铺',
                            width:'80',
                            key: 'shop_name',
                        },
                        {
                            title:'订单提交时间',
                            width:'150',
                            key:'create_time',
                        },
                        {
                            title: '详细',
                            width:'150',
                            render:(h,params) => {
                                let prod_detail = params.row.prod_detail;
                                let link = 'https://haohuo.jinritemai.com/views/product/item2/?id='+params.row.origin_prod_id;
                                return h('a',{
                                    domProps:{
                                        href: link,
                                        target:'_blank'
                                    },
                                },prod_detail)
                            }
                        },
                        {
                            title:'商户备注',
                            width:'100',
                            key:'seller_words'
                        },
                        {
                            title:'用户留言',
                            width:'100',
                            key:'buyer_words',
                        },
                        {
                            title:'下单数量',
                            width:'100',
                            key:'combo_num',
                            render:(h,params) => {
                                let num = params.row.combo_num;
                                let color = 'black';
                                let size = '12px';
                                if(num != 1 || num != '1'){
                                    color = 'red';
                                    size = '16px';
                                }
                                return h('div',{
                                    style:{
                                        'color':color,
                                        'font-size':size
                                    },
                                },num)
                            }
                        },
                        {
                            title:'售价',
                            width:'80',
                            key:'total_amount',
                        },
                        {
                            title:'成本|运费',
                            width:'140',
                            render:(h,params) => {
                                let text = '';
                                let costPrice = params.row.cost_price;
                                let express_fee = params.row.express_fee;
                                if(costPrice){
                                     text = costPrice + ' | '  + express_fee ;
                                }

                                return h('div',{
                                },text)
                            }
                        },

                        {
                            title:'利润|利润率',
                            width:'120',
                            key:'profit',
                            render:(h,params) => {
                                let costPrice = params.row.cost_price;
                                let profit = params.row.profit;
                                let profit_rate = params.row.profit_rate;
                                let text = profit + ' | ' + profit_rate
                                if(costPrice == 0){
                                    text = '';
                                }
                                return h('div',{
                                },text)
                            }
                        },

                        {
                            title:'历史订单',
                            width:'100',
                            render:(h,params) => {
                                let num = params.row.history;
                                let color = 'red';
                                let size = '12px';
                                if(num == 0){
                                    num = '新客';
                                    color = 'green';
                                }
                                return h('div',{
                                    style:{
                                        'color':color,
                                        'font-size':size
                                    },
                                },num)
                            }
                        },
                        {
                            title:'退货理由',
                            width:'200',
                            render:(h,params) => {
                                let refund_reason = params.row.refund_reason;

                                return h('i-input',{
                                    props:{
                                        type:'textarea',
                                        value:vm.tableData1[params.index].refund_reason //此处如何让数据双向绑定
                                    },
                                    on:{
                                        'on-blur':(event) => {
                                            order_id = params.row.order_id;
                                            vm.tableData1[params.index].refund_reason = event.target.value;
                                            this.order_id = order_id;
                                            this.refund_reason = event.target.value;
                                            this.orderEdit();
                                        }
                                    }
                                })
                            }
                        },

                        {
                            title:'头条昵称',
                            width:'100',
                            render:(h,params) => {
                                let nickname = params.row.nickname;

                                if(nickname != '未知'){
                                    return h('div',{
                                        style:{
                                            'color':'green',
                                            'font-size':'12px'
                                        },
                                        on: {
                                            click: () => {
                                                this.markFans(params.row)
                                            }
                                        }
                                    },nickname);
                                }else{
                                    return h('Button',{
                                        props: {
                                            type: 'primary',
                                            size: 'small',
                                        },
                                        on: {
                                            click: () => {
                                                this.markFans(params.row)
                                            }
                                        }
                                    },'备注');
                                }

                            }
                        },



                        {
                            title:'收件人',
                            width:'100',
                            key:'post_receiver',
                        },
                        {
                            title: '颜色',
                            width:'100',
                            key:'color'
                        },
                        {
                            title: '尺码',
                            width:'100',
                            key:'size'
                        },
                        {
                            title: '主播',
                            width:'100',
                            key:'liver'
                        },
                        {
                            title: '跟播',
                            width:'100',
                            key:'wither'
                        },
                        {
                            title: '厂家',
                            width:'150',
                            key:'manu_name'
                        },
                        {
                            title:'订单编号',
                            width:'200',
                            key:'order_id',
                        },

                        {
                            title:'内部货号',
                            width:'100',
                            key:'prod_no',
                        },
                        {
                            title:'收件人手机号',
                            width:'200',
                            key:'post_tel',
                        },
                        {
                            title:'收货地址',
                            width:'200',
                            key:'full_addr',
                        },
                        {
                            title:'更新时间',
                            width:'200',
                            key:'updated_at',
                        },
                    ],
                    tableData1: [],
                    spinShow:false,
                    search:{
                        status:'0',
                        order_id:'',
                        shop_id:'',
                        liver:'',
                        origin_prod_id:'',
                        post_tel:'',
                        back_status: 0,
                        post_receiver:'',
                        detail:'',
                        refund_reason: ''
                    },
                    page: {
                        total: 0,
                        current: 1,
                        pageSize: 30,
                    },
                    colums:[],
                    colums1:[],
                    shops:[],
                    defaultStartTime:'',
                    defaultEndTime:'',
                    options:[],
                    single:false,
                    intervalTime:'',
                    liver:'',
                    wither:'',
                    color:'',
                    size:'',
                    item_num:'',
                    livers:[],
                    editProModal:false,
                    origin_prod_id:'',
                    cost_price:'',
                    express_fee:'',
                    manu_name:'',
                    date_range:[],
                    cards:[],
                    order_id:'',
                    fansModal:false,
                    refund_reason:'',
                    fans:{
                        nickname:'',
                        phone:''
                    },
                    refund:{
                        status:'0',
                        order_id:'',
                        unline_payment:0,
                        unline_express_fee:0,
                        unline_mark:'',
                        unline_trager:''
                    },
                    refundModal:false,
                    status_arr:[
                        {
                            'val':'2',
                            'text':'备货中'
                        },
                        {
                            'val':'3',
                            'text':'已发货'
                        },
                        {
                            'val':'5,9,15,20,26,27,28,29,31,33,36,37,38',
                            'text':'已完成'
                        },
                        {
                            'val':'12,14,16,21',
                            'text':'未发货退款'
                        },
                        {
                            'val':'6,7,8,10,11,13,17,18,19,22,23,24,30,32,34,35,39',
                            'text':'已发货退款'
                        },
                        {
                            'val':"21",
                            'text':"(退款) 订单退款成功"
                        },
                        {
                            'val':'22',
                            'text':'(退款) 售后退款成功'
                        }
                    ]
                }
            },
            mounted(){
                this.token = window.localStorage.getItem('current_user');
                this.data.token = this.token;
                this.defaultStartTime = this.getValidDate(1)+' 06:00:00';
                this.defaultEndTime = this.getValidDate(0)+' 06:00:00';
                this.$Message.config({
                    top: 90,
                    duration: 3
                });
            },
            methods: {
                onSucc(response){
                    if(response.code == 200){
                        this.$Message.info('上传成功');
                    }else{
                        this.$Message.info(response.msg);
                        return;
                    }


                },
                editProModalUp () {
                    this.origin_prod_id = '';
                    this.cost_price = '';
                    this.express_fee = '';
                    this.manu_name = '';
                    this.refund_reason = '';
                    this.editProModal = true;
                },
                orderEdit(){
                    origin_prod_id = this.origin_prod_id;
                    cost_price = this.cost_price;
                    express_fee = this.express_fee;
                    manu_name = this.manu_name;
                    t_order_id = this.order_id;
                    refund_reason = this.refund_reason;
                    start_time = '';
                    end_time = '';

                    if(this.date_range[0] != ''){
                        start_time = this.turnTimeObjToStr(this.date_range[0]);
                        end_time = this.turnTimeObjToStr(this.date_range[1]);
                    }


                    if((!origin_prod_id && !t_order_id) || (!cost_price && !refund_reason) ){
                        this.$Message.info('请填写全信息');
                        return;
                    }
                    axios.post("/admin/order/edit",{
                        token:vm.token,
                        origin_prod_id: origin_prod_id,
                        cost_price: cost_price,
                        express_fee: express_fee,
                        manu_name : manu_name,
                        start_time:start_time,
                        end_time: end_time,
                        order_id: t_order_id,
                        refund_reason:refund_reason

                    })
                        .then(function (response) {
                            if(response.data.code == 400){
                                vm.$Message.error(response.data.msg);
                            }else{
                                vm.$Message.success(response.data.msg);
                            }
                        }) .catch(function (error) {
                            vm.$Message.error('服务器异常');
                    });
                },
                today(){
                    var obj=new Date();
                    var hour    =   obj.getHours();//当前时间(小时)
                    var min    =   obj.getMinutes();//当前时间(分钟)
                    if(hour >= 6 && min >=1){
                        this.defaultStartTime = this.start_time = this.getValidDate(0)+' 06:00:00';
                        this.defaultEndTime = this.end_time = this.getValidDate(-1)+' 06:00:00';
                    }
                },
                orderStatus() {   //  初始化订单状态
                    let that = this;
                    axios.get("/admin/config/get",{
                        params: {
                            token:vm.token,
                            key:'order_status'
                        }

                    })
                    .then(function (response) {
                        vm.options = response.data.result;

                    });
                },
                orderStatusCount() {   //  初始化订单状态
                    let that = this;
                    axios.get("/admin/order/status/count",{
                        params: {
                            token:vm.token,
                            start_time:this.defaultStartTime,
                            end_time:this.defaultEndTime,
                            order_status:this.search.status,
                            liver:this.search.liver
                        }

                    })
                        .then(function (response) {
                            let cards = response.data.result;
                            for(card of cards){
                                let text = '暂无';
                                if(card.back_order_count){
                                    let back_order_count = card.back_order_count;
                                    let back_shop_total_amount = parseInt(card.back_shop_total_amount);
                                    let back_cost_total_price = parseInt(card.back_cost_total_price);
                                    let back_profit = parseInt(back_shop_total_amount - back_cost_total_price);
                                    let back_profit_rate = Math.round(back_profit / back_shop_total_amount * 100) + '%';
                                    text = back_shop_total_amount + ' / ' + back_order_count + ' / '
                                        + back_cost_total_price + ' / '+ back_profit + ' / ' + back_profit_rate

                                }
                                card.text = text;
                            }
                            vm.cards = cards;

                    });
                },
                orderLivers() {   //  初始化主播
                    axios.get("/admin/config/get",{
                        params: {
                            token:vm.token,
                            key:'liver'
                        }

                    })
                    .then(function (response) {
                        vm.livers = response.data.result;
                        console.log(vm.livers);
                    });
                },
                getShop() {   //  初始化店铺
                    axios.get("https://order.youdnr.com/api/temai/order/fxg_shop_list",{
                    })
                    .then(function (response) {
                        vm.shops = response.data.result;
                    });
                },
                orderLiverList(page) {   //  初始化主播列表
                    let that = this;
                    if(this.search.shop_id[0] == ''){
                        this.search.shop_id = ''
                    }
                    console.log(this.search.shop_id);
                    axios.get("/admin/order/liver/count",{
                        params: {
                            token:vm.token,
                            start_time:this.defaultStartTime,
                            end_time:this.defaultEndTime,
                            order_status:this.search.status,
                            order_id:this.search.order_id,
                            shop_id:this.search.shop_id,
                            liver:this.search.liver
                        }

                    })
                    .then(function (response) {
                        vm.tableData = response.data.result;

                    });
                },
                searchList(){   //搜索
                    this.orderLiverList(1);
                    this.orderList(1);
                    this.orderStatusCount();
                },
                dateStartFormat(f,v){   //时间控件
                    this.defaultStartTime = f;
                },
                dateEndFormat(f,v){ //时间控件
                    this.defaultEndTime = f;
                },
                //获取几天前时间日期
                getValidDate(dayCount = 1){
                    curDate = new Date();
                    var preDate = new Date(curDate.getTime() - dayCount*24*60*60*1000);

                    var year = preDate.getFullYear();
                    var month = preDate.getMonth()+1;
                    if(month < 10){
                        month = '0'+ month;
                    }
                    var day = preDate.getDate();
                    if(day < 10){
                        day = '0'+ day;
                    }
                    var time = year + '-' + month + '-' + day;

                    return time;
                },
                //根据时间对象获取时间字符串
                turnTimeObjToStr(preDate){
                    var year = preDate.getFullYear();
                    var month = preDate.getMonth()+1;
                    if(month < 10){
                        month = '0'+ month;
                    }
                    var day = preDate.getDate();
                    if(day < 10){
                        day = '0'+ day;
                    }
                    h = preDate.getHours();// 小时
                    m = preDate.getMinutes(); // 分
                    s = preDate.getSeconds(); // 秒

                    if(h < 10){
                        h = '0'+h;
                    }
                    if(m < 10){
                        m = '0'+m;
                    }
                    if(s < 10){
                        s = '0'+s;
                    }
                    let time = year + '-' + month + '-' + day +' '+h+':'+m+':'+s;
                    return time;
                },
                getHourDate(hourCount){  //  前几个小时的时间
                    curDate = new Date();
                    var preDate = new Date(curDate.getTime() - hourCount*60*60*1000);
                    h = preDate.getHours();// 小时
                    m = preDate.getMinutes(); // 分
                    s = preDate.getSeconds(); // 秒
					var year = preDate.getFullYear();
                    var month = preDate.getMonth()+1;
                    if(month < 10){
                        month = '0'+ month;
                    }
                    var day = preDate.getDate();
                    if(day < 10){
                        day = '0'+ day;
                    }
                    if(h < 10){
                        h = '0'+h;
                    }
                    if(m < 10){
                        m = '0'+m;
                    }
                    if(s < 10){
                        s = '0'+s;
                    }
                    let time = year + '-' + month + '-' + day +' '+h+':'+m+':'+s;
                    return time;
                },
                updateOrder(day){  //同步订单数据
                    var start_time = '';
                    if(day == ''){  //  八个月
                        start_time  = this.getValidDate(20)+' 00:00:00';
                    }else if(day    ==  2){ //两天前
                        start_time  = this.getValidDate(2)+' 00:00:00';
                    }else{  //两小时
                        start_time  = this.getHourDate(2);
                    }

                    vm.$Message.warning('【同步】订单中，请耐心等候！');
                    axios.post("/api/order/fxg",{
                        start_time:start_time
                    })
                    .then(function (response) {
                        if(response.data.code == 400){
                            vm.$Message.error(response.data.msg);
                        }else{
                            vm.$Message.success(response.data.msg);
                        }
                    }) .catch(function (error) {
                        vm.$Message.error('服务器异常');
                    });
                },
                orderList(page = 1) {   //订单列表
                    let that = this;
                    this.spinShow = true;
                    axios.get("/admin/order/list",{
                        params: {
                            token:vm.token,
                            start_time: that.defaultStartTime,
                            end_time: that.defaultEndTime,
                            order_id:that.search.order_id,
                            order_status:this.search.status,
                            page:page,
                            shop_id:this.search.shop_id,
                            liver:this.search.liver,
                            origin_prod_id:this.search.origin_prod_id,
                            post_tel:this.search.post_tel,
                            back_status:this.search.back_status,
                            post_receiver:this.search.post_receiver,
                            detail:this.search.detail,
                            refund_reason:this.search.refund_reason
                        }
                    })
                    .then(function (response) {
                        vm.tableData1 = response.data.result.data;
                        vm.page.total = response.data.result.total;
                        vm.page.current = response.data.result.current_page;
                        vm.page.pageSize = response.data.result.per_page;
                        that.spinShow = false;
                    });
                },
                setTimeUpdate(){    //定时同步订单
                    if(this.single === true){
                        this.intervalTime = setInterval(function () {
                            vm.updateOrder(1);
                        }, 60*1000);
                    }else{
                        clearInterval(this.intervalTime);
                    }
                },
                markFans(row){ //粉丝备注
                    this.fansModal = true;
                    this.fans.phone = row.post_tel;
                    this.fans.nickname  =   '';
                    if(row.nickname != '未知'){
                        this.fans.nickname = row.nickname;
                    }
                },
                markStatus(row){ //退款登记
                    this.refundModal = true;
                    this.refund.order_id = row.order_id;
                    this.refund.status  =   String(row.local_order_status);
                    if(row.unline_mark){
                        this.refund.unline_mark = row.unline_mark;
                    }
                    if(row.unline_express_fee){
                        this.refund.unline_express_fee = row.unline_express_fee;
                    }
                    if(row.unline_payment){
                        this.refund.unline_payment = row.unline_payment;
                    }
                    if(row.unline_trager){
                        this.refund.unline_trager = row.unline_trager;
                    }


                },
                storeMarkFans(){    //保存粉丝备注
                    console.log(this.fans);
                    axios.get('https://fans.youdnr.com/api/fans/store_mark', {
                        params: {
                            nickname:this.fans.nickname,
                            phone:this.fans.phone
                        }
                    }).then((response) => {
                        vm.$Message.success('备注完成');
                        vm.orderList(vm.page.current);
                    });

                },
                storeMarkRefund(){  //线下退款处理
                    console.log(this.refund);
                    axios.get('/admin/order/store_refund', {
                        params: {
                            token:vm.token,
                            order_id:this.refund.order_id,
                            status:this.refund.status,
                            unline_trager:this.refund.unline_trager,
                            unline_mark:this.refund.unline_mark,
                            unline_payment:this.refund.unline_payment,
                            unline_express_fee:this.refund.unline_express_fee
                        }
                    }).then((response) => {
                        vm.$Message.success('登记完成');
                        vm.orderList(vm.page.current);
                    });
                },
                batch() {
                    let ids = [];
                    this.$refs.selection.getSelection().map(item => {
                        ids.push(item.order_id);
                    });
                    return ids;
                }


            },
            computed: {
                combine_link() {
                    return '/admin/order/export?shop_id=' + this.search.shop_id + '&start_time=' + this.defaultStartTime +
                        '&end_time=' + this.defaultEndTime + '&order_id=' + this.search.order_id + '&order_status=' + this.search.status + '&token=' + this.token +
                        '&refund_reason=' + this.search.refund_reason +'&guide_form=Full';
                }

            }


        });

        vm.token = getToken();
        vm.orderStatus();
        vm.orderLivers();
        vm.getShop();
        vm.searchList();

        $("body").addClass("sidebar-collapse");

    </script>

@endsection

